﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter11.Code01.Code08
{
    public class Cloner : ICloneable
    {
        public int Val;
        public Content MyContent = new Content();

        public Cloner(int newVal)
        {
            MyContent.Val = newVal;
        }

        public Cloner()
        {

        }

        public object GetCopy()
        {
            return MemberwiseClone();
        }

        //方式1
        public object Clone()
        {
            Cloner clonedCloner = new Cloner(MyContent.Val);
            return clonedCloner;
        }

        //方式2
        public object Clone2()
        {
            Cloner clonedCloner = new Cloner();
            clonedCloner.MyContent = (Content)MyContent.Clone();
            return clonedCloner;
        }
    }
}
